import { request } from '@umijs/max';

//获取验证码图片
export async function getCaptcha(): Promise<Blob> {
    return request('/captcha', {
      method: 'GET',
      params: {
        type: 'math',
        s: Math.random()
      },
      responseType: 'blob', // 关键配置，指定响应类型为blob
      skipErrorHandler: true // 可选，跳过默认的错误处理
    });
}

//检测验证码是否输入正确
export async function checkCode(body: API.CheckCodeParams, options?: { [key: string]: any }) {
    const formData = new URLSearchParams();
    Object.entries(body).forEach(([key, value]) => {
        formData.append(key, String(value));
    });
    return request('/admin/user/checkCode', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
      },
      data: formData.toString(),
      ...(options || {}),
    });
}
  
//用户登陆
//getResponse: true, //如果需要返回的response值必须要设置这个
export async function userLogin(body: API.LoginParams, options?: { [key: string]: any }) {
    return request('/cfms/common/login', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      getResponse: true,
      data: body,
      ...(options || {}),
      
    });
}
  
//检查用户登陆名
export async function checkLoginName(params?: API.CheckLoginUser) {
    return request('/checkUser', {
      method: 'GET',
      headers: {
        'Content-Type': 'application/json;charset=UTF-8',
      },
      params
    });
}